<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="85px">
      <el-form-item label="项目名称"  prop="baseItemId">
        <virtual-select
          v-model="queryParams.baseItemId"
          :list="baseitemList"
          clearable
          filterable
          placeholder="请选择项目名称"
          label="itemName"
          value="id"
          :keeps-params="10"
          :is-concat="false"
          :is-multiple="false"
          :is-right="false "
        >
        </virtual-select>
      </el-form-item>
      <el-form-item label="描述" prop="describe">
        <el-input
          v-model="queryParams.describe"
          placeholder="请输入描述"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="合格标记" prop="passTag">-->
<!--        <el-input-->
<!--          v-model="queryParams.passTag"-->
<!--          placeholder="请输入合格标记"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="入小结标记" prop="conclusionTag">-->
<!--        <el-input-->
<!--          v-model="queryParams.conclusionTag"-->
<!--          placeholder="请输入入小结标记"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="显示名称" prop="showitemName">-->
<!--        <el-input-->
<!--          v-model="queryParams.showitemName"-->
<!--          placeholder="请输入显示名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['basic:baseitemdescribe:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['basic:baseitemdescribe:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['basic:baseitemdescribe:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['basic:baseitemdescribe:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-close"
          size="mini"
          @click="handleClose"
        >关闭</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baseitemdescribeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目名称" align="center" prop="baseItemName" />
<!--      <el-table-column label="项目名称" align="center" prop="baseItemId" >-->
<!--      <template slot-scope="scope">-->
<!--        <span-->
<!--          v-if="scope.row.baseItemId==item.id" v-for="item in baseitemList" :key="item.id">-->
<!--          {{item.itemName}}-->
<!--        </span>-->
<!--      </template>-->
<!--      </el-table-column>-->
      <el-table-column label="描述" align="center" prop="describe" />
      <el-table-column label="合格标记" align="center" prop="passTag">
        <template slot-scope="scope">
          <el-checkbox
            :true-label="1"
            :false-label="0"
            v-model="scope.row.passTag"
            onclick="return false"
          ></el-checkbox>
        </template>>
      </el-table-column>
      <el-table-column label="入小结标记" align="center" prop="conclusionTag">
        <template slot-scope="scope">
          <el-checkbox
            true-label="1"
            false-label="0"
            v-model="scope.row.conclusionTag"
            onclick="return false"
          ></el-checkbox>
        </template>>
      </el-table-column>
      <el-table-column label="显示项目名称" align="center" prop="showitemName">
        <template slot-scope="scope">
          <el-checkbox
            true-label="1"
            false-label="0"
            v-model="scope.row.showitemName"
            onclick="return false"
          ></el-checkbox>
        </template>>
      </el-table-column>
      <el-table-column label="疾病名称" align="center" prop="diseaseName" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['basic:baseitemdescribe:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['basic:baseitemdescribe:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目基础描述对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="550px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="项目名称" prop="baseItemId">
          <el-select v-model="form.baseItemId" filterable placeholder="请选择项目名称" style="width: 100%" :disabled="true">
            <el-option
              v-for="item in baseitemList"
              :key="item.id"
              :label="item.itemName"
              :value="item.id"/>
          </el-select>
        </el-form-item>
        <el-form-item label="描述" prop="describe">
          <el-input v-model="form.describe" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-col span="9">
        <el-form-item label="合格标记" prop="passTag">
          <el-checkbox
            :true-label="1"
            :false-label="0"
            v-model="form.passTag"
          ></el-checkbox>
        </el-form-item>
        </el-col>
        <el-col span="9">
        <el-form-item label="入小结标记" prop="conclusionTag">
          <el-checkbox
            true-label="1"
            false-label="0"
            v-model="form.conclusionTag"
          ></el-checkbox>
        </el-form-item>
        </el-col>
        <el-col span="5">
        <el-form-item label="显示项目名称" prop="showitemName">
          <el-checkbox
            true-label="1"
            false-label="0"
            v-model="form.showitemName"
          ></el-checkbox>
        </el-form-item>
        </el-col>
        <el-form-item label="疾病名称" prop="diseaseName">
          <el-input v-model="form.diseaseName" type="textarea" placeholder="请输入疾病名称" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBaseitemdescribe, getBaseitemdescribe, delBaseitemdescribe, addBaseitemdescribe, updateBaseitemdescribe } from "@/api/basic/baseitemdescribe";
import { listBaseitem } from '@/api/basic/baseitem'
import VirtualSelect from '@/views/components/Select';

export default {
  name: "Baseitemdescribe",
  components: { VirtualSelect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //基础项目数据
      baseitemList:[],
      // 项目基础描述表格数据
      baseitemdescribeList: [],
      // 默认项目
      defaultItem: "",
      // 默认
      itemId: "",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        baseItemId: null,
        describe: null,
        passTag: null,
        conclusionTag: null,
        showitemName: null,
        diseaseName: null,
        baseItemName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // passTag: [
        //   { required: true, message: "合格标记不能为空", trigger: "blur" }
        // ],
        describe: [
          { required: true, message: "描述不能为空", trigger: "blur" }
        ]
      }
    };
  },
  activated() {
    this.getDetail();
  },
  beforeCreate() {
    listBaseitem({pageNum: 1,
    pageSize: 2000}).then(response => {
    this.baseitemList = response.rows;
  });
  },
  created() {
    // this.getList();

    this.getDetail();
  },
  methods: {
    /** 查询项目基础描述列表 */
    getList() {
      this.loading = true;
      listBaseitemdescribe(this.queryParams).then(response => {
        this.baseitemdescribeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getDetail(){
      var id = this.$route.query.itemId
        this.queryParams.baseItemId = id;
        this.defaultItem = id;
        this.getList();
    },
    setItemName(itemName){
      this.form.baseItemName = itemName;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        baseItemId: null,
        baseItemName: null,
        describe: null,
        passTag: null,
        conclusionTag: null,
        showitemName: null,
        diseaseName: null,
        remark: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目基础描述";
      this.form.baseItemId = this.queryParams.baseItemId
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBaseitemdescribe(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改项目基础描述";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBaseitemdescribe(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBaseitemdescribe(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除项目基础描述编号为"' + ids + '"的数据项？').then(function() {
        return delBaseitemdescribe(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 返回按钮操作 */
    handleClose() {
      const obj = { path: "/company/baseitem" };
      this.$tab.closeOpenPage(obj);
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('basic/baseitemdescribe/export', {
        ...this.queryParams
      }, `baseitemdescribe_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
